package com.prs.crm.service.exchange.impl;

import java.util.Collection;
import java.util.Date;

import org.courser.Util;
import org.courser.service.ServiceSupportImpl;

import com.prs.crm.dao.exchange.OnlinePersonDao;
import com.prs.crm.domain.exchange.OnlinePerson;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.service.exchange.OnlinePersonService;

public class OnlinePersonServiceImpl extends ServiceSupportImpl<OnlinePerson,OnlinePersonDao>
									implements OnlinePersonService{
	
	public void saveLogin(Person person,String ip)
	{
		OnlinePerson online = this.getDao().findOnline(person,ip);
		if (online==null)
		{
			online = new OnlinePerson();
			online.setOper(person);
			online.setIp(ip);
		}
		online.setLoginTime(Util.nowFullTime());
		online.setUpdateTime(online.getLoginTime());
		super.save(online);
	}
	
	public void savePing(Person person,String ip)
	{
		OnlinePerson online = this.getDao().findOnline(person,ip);
		if (online==null)
		{
			online = new OnlinePerson();
			online.setOper(person);
		}
		online.setUpdateTime(Util.nowFullTime());
		super.save(online);
	}
	
	public void removeOverTime(Date limitTime)
	{
		this.getDao().removeOverTime(limitTime);
	}

	@Override
	public int countOnlinePersons() {
		// TODO Auto-generated method stub
		return this.getDao().countOnlinePersons();
	}

	@Override
	public int removeOnlinePerson(Integer id) {
		// TODO Auto-generated method stub
		return this.getDao().removeOnlinePerson(id);
	}

	@Override
	public Collection<OnlinePerson> getAll() {
		// TODO Auto-generated method stub
		return this.getDao().getAll();
	}

	@Override
	public int removePerson(Person person) {
		// TODO Auto-generated method stub
		return this.getDao().removePerson(person);
	}
}
